<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: Helper functions</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_addon_helpers.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Helper functions </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scripthelper/</p>
<p>These helper functions simplify the implemention of common tasks. They can be used as is or can serve as the starting point for your own framework.</p>
<h2><a class="anchor" id="doc_addon_helpers_1"></a>
Public C++ interface</h2>
<div class="fragment"><pre class="fragment"><span class="comment">// Compare relation between two objects of the same type.</span>
<span class="comment">// Uses the object&#39;s opCmp method to perform the comparison.</span>
<span class="comment">// Returns a negative value if the comparison couldn&#39;t be performed.</span>
<span class="keywordtype">int</span> CompareRelation(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keywordtype">void</span> *leftObj, <span class="keywordtype">void</span> *rightObj, <span class="keywordtype">int</span> typeId, <span class="keywordtype">int</span> &amp;result);

<span class="comment">// Compare equality between two objects of the same type.</span>
<span class="comment">// Uses the object&#39;s opEquals method to perform the comparison, or if that doesn&#39;t exist the opCmp method.</span>
<span class="comment">// Returns a negative value if the comparison couldn&#39;t be performed.</span>
<span class="keywordtype">int</span> CompareEquality(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keywordtype">void</span> *leftObj, <span class="keywordtype">void</span> *rightObj, <span class="keywordtype">int</span> typeId, <span class="keywordtype">bool</span> &amp;result);

<span class="comment">// Compile and execute simple statements.</span>
<span class="comment">// The module is optional. If given the statements can access the entities compiled in the module.</span>
<span class="comment">// The caller can optionally provide its own context, for example if a context should be reused.</span>
<span class="keywordtype">int</span> ExecuteString(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *code, <a class="code" href="classas_i_script_module.html" title="The interface to the script modules.">asIScriptModule</a> *mod = 0, <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx = 0);

<span class="comment">// Write registered application interface to file.</span>
<span class="comment">// This function creates a file with the configuration for the offline compiler, asbuild, in the samples.</span>
<span class="comment">// If you wish to use the offline compiler you should call this function from you application after the </span>
<span class="comment">// application interface has been fully registered. This way you will not have to create the configuration</span>
<span class="comment">// file manually.</span>
<span class="keywordtype">int</span> WriteConfigToFile(<a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine, <span class="keyword">const</span> <span class="keywordtype">char</span> *filename);

<span class="comment">// Print information on script exception to the standard output.</span>
<span class="comment">// Whenever the asIScriptContext::Execute method returns asEXECUTION_EXCEPTION, the application </span>
<span class="comment">// can call this function to print some more information about that exception onto the standard</span>
<span class="comment">// output. The information obtained includes the current function, the script source section, </span>
<span class="comment">// program position in the source section, and the exception description itself.</span>
<span class="keywordtype">void</span> PrintException(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx, <span class="keywordtype">bool</span> printStack = <span class="keyword">false</span>);
</pre></div><h2><a class="anchor" id="doc_addon_helpers_2"></a>
Example</h2>
<p>To compare two script objects the application can execute the following code:</p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> Compare(<a class="code" href="classas_i_script_object.html" title="The interface for an instance of a script object.">asIScriptObject</a> *a, <a class="code" href="classas_i_script_object.html" title="The interface for an instance of a script object.">asIScriptObject</a> *b)
{
  <a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine = a-&gt;<a class="code" href="classas_i_script_object.html#a5dda2d380ae1580e15ddf9d95893c57a" title="Return the script engine.">GetEngine</a>();
  <span class="keywordtype">int</span> typeId = a-&gt;<a class="code" href="classas_i_script_object.html#a19c5ab9d8adb0f921bf0b6474d97f468" title="Returns the type id of the object.">GetTypeId</a>();

  <span class="keywordtype">int</span> cmp;
  <span class="keywordtype">int</span> r = CompareRelation(engine, a, b, typeId, cmp);
  <span class="keywordflow">if</span>( r &lt; 0 )
  {
    cout &lt;&lt; <span class="stringliteral">&quot;The relation between a and b cannot be established b&quot;</span> &lt;&lt; endl;
  }
  <span class="keywordflow">else</span>
  {
    <span class="keywordflow">if</span>( cmp &lt; 0 )
      cout &lt;&lt; <span class="stringliteral">&quot;a is smaller than b&quot;</span> &lt;&lt; endl;
    <span class="keywordflow">else</span> <span class="keywordflow">if</span>( cmp == 0 )
      cout &lt;&lt; <span class="stringliteral">&quot;a is equal to b&quot;</span> &lt;&lt; endl;
    <span class="keywordflow">else</span>
      cout &lt;&lt; <span class="stringliteral">&quot;a is greater than b&quot;</span> &lt;&lt; endl;
  }
}
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
